<template>
    <div>
        <router-view name="page_header"></router-view>
        <div>
            <el-card class="box-card">
                <h2>{{ notice.title }}</h2>
                <el-tag size="medium ">发布时间:{{ format(notice.create_time).format }}</el-tag>
                <el-tag size="medium ">修改时间:{{ format(notice.update_time).format }}</el-tag>
                <p>
                    {{ notice.content }}
                </p>
            </el-card>
        </div>
        <router-view name="page_foot"></router-view>
    </div>
</template>
<script>
import axios from 'axios';
import dateTime from '@/utils/date_time';
export default {
    data() {
        return {
            notice: []
        }
    },
    methods: {
        format(create_time) {
            return dateTime.dateTime(create_time)
        }
    },
    created: function () {
        let that = this;
        //防止刷新时跳转到其它位置
        let id = that.$route.params.notice_id;
        if (!that.$route.params.notice_id) {
            id = window.localStorage.getItem("notice_id");
        }
        axios.get('http://127.0.0.1:5000/api/notice/get_obj', {
            params: {
                notice_id: id
            }
        })
            .then(function (response) {
                console.log(response.data.result.obj);
                that.notice = response.data.result.obj;
                //保存到本地仓库
                window.localStorage.setItem("notice_id", response.data.result.obj.notice_id);
            })
            .catch(function (error) {
                console.log(error);
            })
            .then(function () {
                // 总是会执行
            })
    }
}
</script>
<style></style>
